home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 April
/
EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso
/
EARCD
/
comm
/
bbs
/
Hydra11s.lha
/
HBBS
/
Source
/
Doors_System
/
CLIProtocol
/
Main.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-10-31
|
7KB
|
299 lines
/*
XPR_External door.
This door calls other pre-written CLS XPR transfer programs that use the
XPR<name>.library files.
N_ND->ActiveDoor->SystemOptions
===============================
UPLOAD|DOWNLOAD
dooroptions
===========
P=<xpr<lib>.library>
D=<download path> you should normally only specify one place and that should
be HBBS:Nodes/NodeX/Playpen (or wherever the node's playpen is..)
U=<file to upload> you can specify more than one of these only if the protocol
is a batch upload protocol
e.g.
U=dh2:warez/miggy/hotsoft.lha
U=dh2:warez/miggy/newsoft.lha
....
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_protos.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <libraries/xproto.h> // XPR protocol stuff...
#include <devices/serial.h>
#include <devices/timer.h>
#ifdef __SASC
int CXBRK(void) { return(0); }
int _CXBRK(void) { return(0); }
void chkabort(void) {}
#endif
#include <HBBS/ANSI_Codes.h>
#include <HBBS/Defines.h>
#include <HBBS/types.h>
#include <HBBS/structures.h>
#include <HBBS/hbbscommon_protos.h>
#include <HBBS/hbbscommon_pragmas.h>
#include <HBBS/Hbbsnode_protos.h>
#include <HBBS/Hbbsnode_pragmas.h>
#include <HBBS/release.h>
char *versionstr="$VER: CLIProtocol "RELEASE_STR;
long __stack=16384;
struct Library *HBBSCommonBase=NULL;
struct Library *HBBSNodeBase=NULL;
struct BBSGlobalData *BBSGlobal=NULL;
struct NodeData *N_ND=NULL;
int N_NodeNum=-1;
struct List *ul_filelist=NULL;
long ul_files=0;
long currentul=1;
struct List *dl_pathlist=NULL;
long dl_paths=0;
struct CfgFileData *CfgFile=NULL;
char *XE_Program=NULL;
char *XE_Params=NULL;
char *XE_SendStr=NULL;
char *XE_RecvStr=NULL;
V_BOOL XE_CDTODIR=TRUE;
UBYTE *GetNodeStr(struct List *lh,ULONG n)
{
struct Node *ln;
for (ln = lh->lh_Head; n--; ln = ln->ln_Succ);
return (ln->ln_Name);
}
static VOID cleanup(ULONG num)
{
if (HBBSNodeBase)
{
HBBS_CleanUpDoor();
CloseLibrary (HBBSNodeBase);
}
if (HBBSCommonBase)
{
HBBS_CleanUpCommon();
CloseLibrary (HBBSCommonBase);
}
if (num) printf("Door Error = %d\n",num);
exit(0);
}
static VOID init(char *name)
{
if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
{
cleanup(1);
}
if (!(HBBS_InitCommon()))
{
cleanup(2);
}
if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
{
cleanup(3);
}
if (!(HBBS_InitDoor(N_NodeNum,name)))
{
cleanup(4);
}
SetProgramName(name);
}
void Xfer( void )
{
char runstr[8192];
char tmpstr[4098];
LONG retval;
struct Node *node;
BPTR FL,NFL;
strcpy (runstr,XE_Program);
strcat (runstr," ");
strcat (runstr,XE_Params);
if (ul_files>0)
{
replace(runstr,runstr,"{MODE}",XE_SendStr);
}
else
{
replace(runstr,runstr,"{MODE}",XE_RecvStr);
if (XE_CDTODIR)
{
if (FL=Lock(dl_pathlist->lh_Head->ln_Name,ACCESS_READ))
{
NFL=CurrentDir(FL);
UnLock(NFL);
}
}
}
sprintf(tmpstr,"%d",N_ND->NodeDevice.SerialBaud);
replace(runstr,runstr,"{BAUD}",tmpstr);
sprintf(tmpstr,"%d",N_ND->NodeDevice.SerialUnit);
replace(runstr,runstr,"{UNIT}",tmpstr);
replace(runstr,runstr,"{DEVICE}",N_ND->NodeDevice.SerialDevice);
tmpstr[0]=0;
if (ul_files>0)
{
for (node = ul_filelist->lh_Head ; node->ln_Succ ; node =node->ln_Succ)
{
if (node!=ul_filelist->lh_Head) strcat(tmpstr," ");
strcat(tmpstr,node->ln_Name);
}
}
else
{
for (node = dl_pathlist->lh_Head ; node->ln_Succ ; node =node->ln_Succ)
{
if (node!= dl_pathlist->lh_Head) strcat(tmpstr," ");
strcat(tmpstr,node->ln_Name);
}
}
replace(runstr,runstr,"{FILES}",tmpstr);
retval=HBBS_RunDOSCMD(runstr,FALSE);
if ((N_ND->LoginType==LOGIN_REMOTE) && (CarrierLost()))
{
N_ND->OnlineStatus=OS_OFFLINE;
}
sprintf(tmpstr,"%d",retval);
DOOR_Return(tmpstr);
}
void DoorMain(int argc,char *argv[])
{
int loop,p;
char outstr[1024];
BOOL Initialized=FALSE;
if (ul_filelist=HBBS_CreateList())
{
if (dl_pathlist=HBBS_CreateList())
{
for(loop=3;loop<argc;loop++) // if there are any parameters then display them
{
switch(toupper(argv[loop][0]))
{
case 'U' :
if (NewStrNode(&argv[loop][2],ul_filelist)==ERR_NO_ERROR)
{
ul_files++;
}
break;
case 'D' :
if (NewStrNode(&argv[loop][2],dl_pathlist)==ERR_NO_ERROR)
{
dl_paths++;
}
break;
default:
DOOR_WriteText("Unknown Option Specified!\r\n");
break;
}
}
strcpy(outstr,argv[0]);
if ((p=iposition(".HBBS",outstr))==(strlen(outstr)-5))
{
outstr[p]=0; //terminate string
}
strcat(outstr,"_");
strcat(outstr,argv[2]); //config number/string
strcat(outstr,".CFG");
if (CfgFile=HBBS_LoadConfig(outstr,LCFG_NONE))
{
if (HBBS_GetSetting(CfgFile,(void *)&XE_Program,VTYPE_STRING,"Program",OPT_SINGLE) &&
HBBS_GetSetting(CfgFile,(void *)&XE_Params,VTYPE_STRING,"Params",OPT_SINGLE))
{
HBBS_GetSetting(CfgFile,(void *)&XE_SendStr,VTYPE_STRING,"SendStr",OPT_SINGLE);
HBBS_GetSetting(CfgFile,(void *)&XE_RecvStr,VTYPE_STRING,"RecvStr",OPT_SINGLE);
HBBS_GetSetting(CfgFile,(void *)&XE_CDTODIR,VTYPE_BOOL,"CDToDir",OPT_SINGLE);
if ((ul_files || dl_paths))
{
Initialized=TRUE;
Xfer();
}
}
else
{
DOOR_WriteText("\r\nConfig File Error\r\n");
}
HBBS_FlushConfig(CfgFile);
}
FreeStrList(dl_pathlist);
}
FreeStrList(ul_filelist);
}
if (!Initialized) DOOR_WriteText(" Failed - Check Parameters!\r\n");
}
int main(int argc,char *argv[])
{
if (sscanf(argv[1],"%d",&N_NodeNum)==0)
{
printf("Invalid/No Paramaters for door!\n");
exit (20);
}
init("CLIProtocol");
if (BBSGlobal=HBBS_GimmeBBS())
{
if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
{
DoorMain(argc,argv);
}
}
cleanup(0);
}